﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Explorer;
using Microsoft.VisualStudio.SharePoint.Explorer.Extensions;
using SPVSX.Explorer.Extensions.Properties;

namespace SPVSX.Explorer.Extensions
{
    partial class ListNodeExtension
    {
        /// <summary>
        /// Initialise the events for a style library
        /// </summary>
        /// <param name="nodeType">The node type</param>
        public void InitializeStyleLibrary(IExplorerNodeType nodeType)
        {
            nodeType.NodeChildrenRequested += StyleLibrary_NodeChildrenRequested;
            nodeType.NodeMenuItemsRequested += StyleLibrary_NodeMenuItemsRequested;
            nodeType.NodePropertiesRequested += StyleLibrary_NodePropertiesRequested;
        }

        void StyleLibrary_NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            //throw new NotImplementedException();
        }

        void StyleLibrary_NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
        {
            //throw new NotImplementedException();
        }

        /// <summary>
        /// Get the style nodes if the site is the root site
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The ExplorerNodeEventArgs object</param>
        void StyleLibrary_NodeChildrenRequested(object sender, ExplorerNodeEventArgs e)
        {
            // The GetStyles argument is a delegate that Visual Studio calls 
            // to create the child nodes under the Style library node.
            IListNodeInfo annotation = e.Node.GetAnnotation<IListNodeInfo>();
            if ((annotation != null) && (annotation.Title == Resources.StyleLibraryNode_Label))
            {
                //Only render the node if the site is the root
                GenericFolderNode.Create(e.Node,
                    Resources.StylesNode_Label,
                    Resources.StylesNode.ToBitmap(),
                    StyleLibraryNodeTypeProvider.GetStyles);
            }
        }
    }
}
